﻿using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Core.SeedData
{
    public abstract class ExcelSeedData<T> where T : class, new()
    {
        public virtual string ExcelPath { get; }
        public virtual List<T> Read()
        {
            try
            {
                // 检查文件是否存在
                if (!File.Exists(ExcelPath))
                {
                    throw new FileNotFoundException($"Excel 文件 {ExcelPath} 未找到。");
                }

                // 读取excel数据
                var data = MiniExcel.Query<T>(ExcelPath);

                return data.ToList();
            }
            catch (Exception ex)
            {
                // 处理异常
                Console.WriteLine($"读取 Excel 文件时发生错误: {ex.Message}");
                return null;
            }
        }
    }
}
